package cn.loan.controller;

import cn.loan.config.key.StatusCode;
import cn.loan.entity.FeedBack;
import cn.loan.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;

/**
 * @Author: 毛苏宇
 * @Description: 反馈页面
 * @Date: Create in 12:46 2019/3/20
 */
@Controller
@RequestMapping("/feedback")
public class FeedBackController {

    @Autowired private FeedBackService feedBackService;

    /**
     * 跳转到反馈建议页面
     * @return 反馈建议页面
     */
    @GetMapping("/opinion")
    public String opinion(){
        return "/opinion";
    }


    /**
     * 提交反馈建议
     * @param feedBack 用户反馈的意见和建议
     * @return  提交的状态
     */
    @PostMapping("/submitFeedBack")
    @ResponseBody
    public String submitFeedBack(FeedBack feedBack){
        try{
            feedBack.setFeedback_time(new Timestamp(System.currentTimeMillis()));   //添加提交时间
            boolean flag = feedBackService.submitFeedback(feedBack);    //提交反馈  true=成功,false=失败
            return flag==true?StatusCode.STATUS_SUCCESS:StatusCode.STATUS_FAIL; //返回提交的状态
        }catch (Exception e){
            e.printStackTrace();
            return StatusCode.STATUS_ERROR; //发生异常
        }
    }

}
